#include "widget.h"
#include "ui_widget.h"
#include <QLabel>
#include <QTreeWidget>
#include <QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    // 为Tab 1添加控件
    QLabel* label1 = new QLabel(ui->tab);
    label1->setText("tab1");
    label1->resize(100,50);

    // 为Tab 2添加控件
    QTreeWidget* tree = new QTreeWidget(ui->tab_2);
    tree->setHeaderLabel(QString("根节点"));
    tree->resize(500,300);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_add_clicked()
{
    // 获取标签个数
    int count = ui->tabWidget->count();
    // 添加标签
    QWidget* add = new QWidget();
    ui->tabWidget->addTab(add,QString("Tab ") + QString::number(count + 1));
    ui->tabWidget->setCurrentIndex(count);
}

void Widget::on_pushButton_sub_clicked()
{
    // 获取当前选中标签
    int count = ui->tabWidget->currentIndex();
    // 删除所选标签
    ui->tabWidget->removeTab(count);
}

void Widget::on_tabWidget_currentChanged(int index)
{
    qDebug() << "Index: " << index;
}
